package dingding;


import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

public class Person {

    private int age;
    private String name;
    private Person person;

    public Person(String name, int age) {
        this.age = age;
        this.name = name;
        System.out.println("构造函数Person(有参数)执行");
    }

    public Person() {
        System.out.println("构造函数Person(无参数)执行");
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }


    public static Map<String,String> map = new HashMap<>();

    public static void main(String[] args) throws Exception {


        //当我不想 newInstance初始化的时候执行空参数的构造函数的时候
        //可以通过字节码文件对象方式 getConstructor(paramterTypes) 获取到该构造函数
        String classname = "dingding.Person";
        //寻找名称的类文件，加载进内存 产生class对象
        Class cl = Class.forName(classname);
        //获取到Person(String name,int age) 构造函数
        Constructor con = cl.getConstructor(String.class, int.class);

        //通过构造器对象 newInstance 方法对对象进行初始化 有参数构造函数
        Object obj = con.newInstance("神奇的我", 12);
        System.out.println(con);
        System.out.println(obj);


        map.put("a","a");

        getMap(map);

    }

    public static Map<String,String> getMap(Map<String,String> map) {
        return map;
    }
}